package Aplicacion;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.InputStream;
import java.net.URL;
import javazoom.jl.player.advanced.AdvancedPlayer;
import javax.swing.*;

public class MP3Player extends JFrame{
    private AdvancedPlayer pl;
    private URL url;
    private InputStream in;
    
    public MP3Player(){
    	
    }

    public void Play(String path){
        try{
            url = new URL(path);
            in = url.openStream();
            pl = new AdvancedPlayer(in);

            pl.getPlayBackListener();
            pl.play();             
        }
        catch(Exception e){
            System.out.println("Feil: "+e);
        }
    }
    
    public void playDaemon (final String path) {
    	Thread player = new Thread(new Runnable () {
    		@Override
    		public void run() {
    			try{
    	            url = new URL(path);
    	            in = url.openStream();
    	            pl = new AdvancedPlayer(in);

    	            pl.getPlayBackListener();
    	            pl.play();             
    	        }
    	        catch(Exception e){
    	            System.out.println("Feil: "+e);
    	        }
    		}	
    	});
    	player.start();
    }

    public void stop () {
    	if (pl != null) pl.close();
    }
}